<template>
	<view class="session-wrap">
		<u-navbar
			backIconColor="#FFFFFF"
			:background="{background: 'linear-gradient(90deg,#615CED,#8286F2)'}"
			:border-bottom="false"
			title="我的考生"
			titleColor="#FFFFFF"
			height="88">
		</u-navbar>

		<view class="search-top" :style="{top: offsetTop}">
			<view class="search-content">
				<view class="search-item">
					<image src="../../static/ic_search.png" mode=""></image>
					<input
						class="search-input"
						placeholder="请输入关键词搜索"
						placeholder-style="font-size: 26rpx; color: #B1B1B1;"
						type="text"
						@confirm="doSearch"
						v-model="search"
					/>
				</view>
			</view>

			<view class="select-wrap">
				<view class="select-left" @click="isPickLeft=true">
					<view class="left-title">
						{{pickLefts[pickLeftIndex].title}}
					</view>
					<image src="../../static/ic_arrow_down.png" mode=""></image>
				</view>
				<view class="select-right" @click="isPickRight=true">
					<view class="rightarea">{{pickRights.length > 0 ? pickRights[pickRightIndex].name : '选择地区'}}</view>
					<image src="../../static/ic_arrow_down.png" mode=""></image>
				</view>
			</view>
		</view>

		<view class="session-list">
			<view class="session-item" v-for="(item,index) in lists" :key="index" @click="student(item)">
				<view class="item-top">
					<view class="name"> {{item.name?item.name:''}}</view>
					<image v-if="item.examination_status == 4" src="../../static/ic_tips.png"  mode="scaleToFill"></image>
					<view class="status" :style="{color: item.examination_status==4?'#E93B3D':'#000000'}">{{item.examination_status == 1 ? '未考试' : item.examination_status == 2 ? '未评定' : item.examination_status == 3 ? '已评定' : item.examination_status == 4 ? '没有打成绩' : ''}}</view>
				</view>

				<view class="item-content">
					<view style="flex: 1;">
						<view class="zhuanye">
							<view class="fangkuai"></view>
							<view class="zytxt">
								考试专业：{{item.major?item.major:''}}
							</view>
						</view>
						<view class="zhunkaozheng">
							<view class="fangkuai"></view>
							<view class="zkztxt">准考证号：{{item.examination_number?item.examination_number:''}}</view>
						</view>
						<view class="score">
							<view class="fangkuai"></view>
							<view class="scoretxt">
								考试成绩：{{item.evaluate?item.evaluate:''}}
							</view>
						</view>
					</view>

					<view class="item-others">
						<view class="kaoshi">
							<view class="fangkuai"></view>
							<view class="zytext">
								考试专业：{{item.Grade?item.Grade:''}}
							</view>
						</view>
						<view class="exarea">
							<view class="fangkuai"></view>
							<view class="areatxt">
								地区：{{item.region?item.region:''}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 状态 -->
		<u-picker
			v-model="isPickLeft"
			mode="selector"
			:default-selector="[pickLeftIndex]"
			:range="pickLefts"
			range-key="title"
			@confirm="pickLeftConfirm">
		</u-picker>
		<!-- 切换市 -->
		<u-picker
			v-model="isPickRight"
			mode="selector"
			:default-selector="[pickRightIndex]"
			:range="pickRights"
			range-key="name"
			@confirm="pickRightConfirm">
		</u-picker>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: '',
			offsetTop: 0,
			search: '',
			lists: [],
			isPickLeft: false,
			pickLefts: [
				{
					id: 0,
					title: '全部'
				}, 
				{
					id: 1,
					title: '已考完'
				}, 
				{
					id: 2,
					title: '未评定'
				}
			],
			pickLeftIndex: 0,
			isPickRight: false,
			pickRights: [],
			pickRightIndex: 0,
			page: 1
		}
	},
	onPullDownRefresh() {
		this.page = 1;
		this.getLists();
	},
	onReachBottom() {
		this.getLists();
	},
	onLoad(ops) {
		this.id = ops?.id || '';
		let sinfo = uni.getSystemInfoSync();
		this.offsetTop = sinfo.statusBarHeight + uni.upx2px(88);
		this.getRegion();
	},
	onShow() {
		uni.$off('sign');
		uni.$on('sign', (id) => {
			let filter = this.lists?.filter(it => it.id == id);
			if (filter?.length > 0) filter[0].examination_status = 3;
		});
	},
	methods: {
		doSearch() {
			this.page = 1
			this.getLists();
		},
		pickLeftConfirm(e) {
			this.pickLeftIndex = e[0];
			this.page = 1;
			this.getLists();
		},
		pickRightConfirm(e) {
			this.pickRightIndex = e[0];
			this.page = 1;
			this.getLists();
		},
		student(item) {
			uni.navigateTo({
				url: `student?id=${item.id}`
			});
		},
		// 获取考生列表
		getLists() {
			let that = this;
			uni.request({
				url: `${that.$api.baseUrl}${that.$api.candidateList}`,
				method: 'POST',
				timeout: 30000,
				data: {
					id: that.id,
					name: that.search,
					type: that.pickLefts[that.pickLeftIndex].id,
					region: that.pickRights[that.pickRightIndex]?.id,
					offset: that.page
				},
				header: {
					'authtoken': that.$auth.token(that.$api.candidateList)
				},
				success(res) {
					if (res.data?.code == 1) {
						that.lists = that.page == 1 ? res.data?.data?.information :
						that.lists.concat(res.data?.data?.information)
						if (res.data?.data?.information?.length > 0) that.page++
					} else {
						uni.showToast({
							title: res.data?.msg || '获取数据失败',
							icon: 'none'
						});
					}
				},
				fail(err) {
					uni.showToast({
						title: '获取数据失败',
						icon: 'none'
					});
				},
				complete() {
					uni.stopPullDownRefresh();
				}
			})
		},
		// 获取地区列表
		getRegion() {
			let that = this;
			uni.request({
				url: `${that.$api.baseUrl}${that.$api.region}`,
				method: 'POST',
				timeout: 30000,
				header: {
					'authtoken': that.$auth.token(that.$api.region)
				},
				success(res) {
					if (res.data?.code == 1) {
						that.pickRights = that.pickRights.concat(res.data?.data?.children)
						that.getLists()
					} else {
						uni.showToast({
							title: res.data?.msg || '获取数据失败',
							icon: 'none',
						})
					}
				},
				fail(err) {
					uni.showToast({
						title: '获取数据失败',
						icon: 'none'
					})
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
page {
	background-color: #F8F8F8;
}
.session-wrap{
	.search-top{
		position: fixed;
		width: 100%;
		z-index: 9999;
		.search-content{
			width: 100%;
			height: 97rpx;
			background: linear-gradient(90deg,#615CED,#8286F2);
			padding-top: 5rpx;
			.search-item{
				display: flex;
				flex-direction: row;
				width: 670rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 32rpx;
				margin-left: 40rpx;
				align-items: center;
				padding: 0 25rpx 0 25rpx;
				image{
					width: 33rpx;
					height: 33rpx;
					margin-right: 13rpx;
				}
				.search-input{
					font-size: 26rpx;
					line-height:26rpx;
					color: #333333;
					flex: 1;
				}
			}
		}
		.select-wrap{
			width: 100%;
			height: 90rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			background-color: #FFFFFF;
			.select-left{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				flex: 1;
				.left-title{
					font-size: 30rpx;
					line-height: 30rpx;
					color: #333333;
				}
				image{
					width: 14rpx;
					height: 7rpx;
					margin-left: 7rpx;
				}
			}
			.select-right{
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				flex: 1;
				.rightarea{
					font-size: 30rpx;
					line-height: 30rpx;
					color: #333333;
				}
				image{
					width: 14rpx;
					height: 7rpx;
					margin-left: 7rpx;
				}
			}
		}
	}
	.session-list{
		padding-top: 207rpx;
		.session-item{
			width: 690rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 0 0 20rpx 30rpx;
			padding: 30rpx;
			.item-top{
				display: flex;
				flex-direction: row;
				align-items: center;
				width: 100%;
				.name{
					font-size: 28rpx;
					font-weight: bold;
					color: #000000;
					line-height: 28rpx;
					flex: 1;
				}
				image{
					width: 27rpx;
					height: 27rpx;
					margin: 0 10rpx 0 10rpx;
				}
				.status{
					font-size: 28rpx;
					font-weight: bold;
					line-height: 28rpx;
				}
			}
			.item-content{
				display: flex;
				flex-direction: row;
				width: 100%;
				.zhuanye{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 30rpx;
					.fangkuai{
						width: 6rpx;
						height: 6rpx;
						background: #615CED;
						margin-left: 10rpx;
					}
					.zytxt{
						font-size: 24rpx;
						color: #333333;
						line-height: 24rpx;
						margin-left: 10rpx;
					}
				}
				.zhunkaozheng{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 20rpx;
					.fangkuai{
						width: 6rpx;
						height: 6rpx;
						background: #615CED;
						margin-left: 10rpx;
					}
					.zkztxt{
						font-size: 24rpx;
						color: #333333;
						line-height: 24rpx;
						margin-left: 10rpx;
					}
				}
				.score{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 20rpx;
					.fangkuai{
						width: 6rpx;
						height: 6rpx;
						background: #615CED;
						margin-left: 10rpx;
					}
					.scoretxt{
						font-size: 24rpx;
						color: #333333;
						line-height: 24rpx;
						margin-left: 10rpx;
					}
				}
			}
			.item-others{
				flex: 1;
				.kaoshi{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 30rpx;
					.fangkuai{
						width: 6rpx;
						height: 6rpx;
						background: #615CED;
						margin-left: 10rpx;
					}
					.zytext{
						font-size: 24rpx;
						color: #333333;
						line-height: 24rpx;
						margin-left: 10rpx;
					}
				}
				.exarea{
					display: flex;
					flex-direction: row;
					align-items: center;
					margin-top: 20rpx;
					.fangkuai{
						width: 6rpx;
						height: 6rpx;
						background: #615CED;
						margin-left: 10rpx;
					}
					.areatxt{
						font-size: 24rpx;
						color: #333333;
						line-height: 24rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
}
</style>
